﻿    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.SqlClient;

    namespace Hotel
    {
    public partial class TypeRoom : Form
    {
    public TypeRoom()
    {
        InitializeComponent();
    }
    BindingSource bdS = new BindingSource();
    CNDatabase dt = new CNDatabase();
    private void TypeRoom_Load(object sender, EventArgs e)
    {
        loadData();
    }
    
    private void loadData() {
        try
        {
            string qr = "select * from TypeRoom";
            
            bdS.DataSource = dt.getDataset(qr).Tables[0];
            grvTypeRoom.DataSource = bdS;
            bindingNavigator1.BindingSource = bdS;
            this.TbIDType.DataBindings.Add("Text", bdS, "IDTypeRoom");
            this.TbTypeRoom.DataBindings.Add("Text", bdS, "NameType");
            this.TbPrice.DataBindings.Add("Text", bdS, "Price");
            this.TbAldut.DataBindings.Add("Text", bdS, "AdultBed");
            this.TbChild.DataBindings.Add("Text", bdS, "ChildBed");
            this.TbDes.DataBindings.Add("Text", bdS, "Description");
        }
        catch (Exception) {
            dt.closeConnect();
        }
        
    }
  
    //Cap nhat phong
    private void BtAddRoom_Click(object sender, EventArgs e)
    {
        try
        {
            string qr = "UPDATE TypeRoom SET [NameType] = '" + TbTypeRoom.Text + "',[Price] = '"
                    + TbPrice.Text + "',[AdultBed] = '" + TbAldut.Text + "',[ChildBed] = '"
                    + TbChild.Text + "',[Description] = '" + TbDes.Text + "' WHERE IDTypeRoom='" + TbIDType.Text + "'";
            dt.xlExecuteNonQuery(qr);
            MessageBox.Show("Updated room's information successfully !", "Information", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                     
            loadData();
        }
        catch (Exception)
        {
            dt.closeConnect();
            MessageBox.Show("Try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
        }
    }

    //Xoa Textbox
    private void LbClear_Click(object sender, EventArgs e)
    {
        TbIDType.Text = "";
        TbTypeRoom.Text = "";
        TbPrice.Text = "";
        TbAldut.Text = "";
        TbChild.Text = "";
        TbDes.Text = "";
    }


    //--------------------Bat su kien, chi cho nhap so------------------------------//

    private void TbIDType_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (!Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar))
        {
            MessageBox.Show("Enter only numeric values in this field.","Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            e.Handled = true;
        }
    }

    private void TbPrice_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (!Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar))
        {
            MessageBox.Show("Enter only numeric values in this field.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            e.Handled = true;
        }
    }

    private void TbAldut_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (!Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar))
        {
            MessageBox.Show("Enter only numeric values in this field.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            e.Handled = true;
        }
    }

    private void TbChild_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (!Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar))
        {
            MessageBox.Show("Enter only numeric values in this field.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            e.Handled = true;
        }
    }

    private void BtAddNew_Click(object sender, EventArgs e)
    {
        try
        {
            string qr = "INSERT INTO TypeRoom(IDTypeRoom, NameType, Price, AdultBed, ChildBed, Description) values ('"
                + TbIDType.Text + "', '" + TbTypeRoom.Text + "', '" + TbPrice.Text + "', '"
                + TbAldut.Text + "', '" + TbChild.Text + "', '" + TbDes.Text + "')";
            dt.xlExecuteNonQuery(qr);
            MessageBox.Show("Inserted new room successfully !", "Information", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            loadData();
        }
        catch (Exception)
        {
            dt.closeConnect();
            MessageBox.Show("Try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
        }
    }
    //--------------------------------------------------------------------------//
    

  }
        
        

    //private void btAddNewRoom_Click(object sender, EventArgs e)
    //{
    //    try
    //    {
    //        string status = "";
    //        if (rb1.Checked) //Nếu click vào NULL- Thay đổi lại bên interface
    //            status = "NULL";
    //        if (rb2.Checked)//FULL
    //            status = "FULL";
    //        if (rb3.Checked)//ORDER
    //            status = "ORDER";

    //        string qr = "INSERT INTO Room(NameRoom,IDTypeRoom,Status,Description) VALUES('"
    //            + txtRoomName.Text + "', '" + cbType.SelectedValue + "', '" + status + "', '" + txtDes.Text + "')";
    //        dt.xlExecuteNonQuery(qr);
    //        MessageBox.Show("Insert Room success");
    //        loadData();
    //    }
    //    catch (Exception) {
    //        MessageBox.Show("Error! Try again");
    //    }


    }

    //private void label11_Click(object sender, EventArgs e)
    //{
    //    txtDes.Text = "";
    //    txtRoomName.Text = "";

    //}

   

       

      
    

    
    //}

